package com.zy.base;

import android.app.Application;
import android.content.Context;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.zy.untils.CrashHandler;


public abstract class BaseApplication extends Application {
    public static Context mContext;
    CrashHandler crashHandler;

    private static BaseApplication instance;
    private String TAG="BaseApplication";
    public static BaseApplication getApplication() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        /**
         * 初始化抓去异常
         * */
        crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());


        mContext = this;
        initLog();
        initARouter();
    }

    /**
     * 初始化路由
     */
    private void initARouter() {
//        if (BuildConfig.DEBUG) {           // These two lines must be written before init, otherwise these configurations will be invalid in the init process
//            ARouter.openLog();     // Print log
//            ARouter.openDebug();   // Turn on debugging mode (If you are running in InstantRun mode, you must turn on debug mode! Online version needs to be closed, otherwise there is a security risk)
//        }
//        ARouter.init(this);
    }

    private void initLog() {

        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(true)  // (Optional) Whether to show thread info or not. Default true
                .methodCount(1)         // (Optional) How many method line to show. Default 2
                .methodOffset(2)        // (Optional) Hides internal method calls up to offset. Default 5
//                .logStrategy(new CustomStrategy(new Handler()))// (Optional) Changes the log strategy to print out. Default LogCat
                .tag("zy_music")   // (Optional) Global tag for every log. Default PRETTY_LOGGER
                .build();

        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        Logger.e(TAG+"程序终止");
//        ARouter.init(this);
    }
}
